﻿using Xejen.Ipc.Framework.Flows;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Xejen.Ipc.Framework.Steps
{
    /// <summary>
    /// 表示步骤
    /// </summary>
    /// <typeparam name="TData"><inheritdoc cref="IFlow{TData}" path="/typeparam[@name='TData']"/></typeparam>
    /// <creator>marc</creator>
    public interface IStep<TData>
        where TData : new()
    {
        /// <summary>
        /// 步骤唯一Id
        /// </summary>
        int Id { get; }
        /// <summary>
        /// 步骤的名称
        /// </summary>
        string Name { get; }

        /// <summary>
        /// 步骤进入时的事件
        /// </summary>
        event EventHandler<StepEventArgs<TData>> Started;
        /// <summary>
        /// 步骤出去时的事件
        /// </summary>
        event EventHandler<StepEventArgs<TData>> Completed;
        /// <summary>
        /// 步骤内发生错误时的事件
        /// </summary>
        event EventHandler<ErrorEventArgs<TData>> Error;

        /// <summary>
        /// 执行步骤
        /// </summary>
        /// <param name="context"><inheritdoc cref="IFlowExecutionContext{TData}" path="/summary"/></param>
        /// <param name="cancellationToken">取消的令牌</param>
        Task ExecuteAsync(IFlowExecutionContext<TData> context, CancellationToken cancellationToken = default);
    }
}
